<?php

class Assignee {
	
	const ACCOUNT_KEY_LEN = 16;
	
	public function factory($id)
	{
		
		if(substr($id,0,1) == '-')
		{
			$assigneeModel = new Accounts;
			$select = $assigneeModel->select();
			$select->where('acc_n = ?', substr($id,1));
			
			$found = $assigneeModel->fetchAll($select);
			
			

			if(count($found) > 0)
				return $found->current(); 
			
		}
		
		$assigneeModel = (strlen($id) == self::ACCOUNT_KEY_LEN) ? new Accounts : new Persons;
		
		$found = $assigneeModel->find($id);

		if(count($found) > 0)
			return $found->current();

		throw new Assignee_Exception_NotFound('Cant found assignee by ID: ' . $id);
		
		
	}
}
